package b2.scene.fight.skills
{
	import b2.scene.fight.PlayState;
	import b2.scene.fight.TankSprite;
	
	import com.greensock.TweenLite;
	
	public class ExplosiveSelf extends AreaHarm
	{
		private var isReady:Boolean;
		
		public function ExplosiveSelf(tankId:int, tankSide:int ,level:int, skillArgs:Object)
		{
			super(tankId, tankSide ,level, skillArgs);
			coolDown = 3;
		}
		
		public override function checkSkillTriggerPremise(x:int, y:int, direction:int):Boolean
		{
			if (super.checkSkillTriggerPremise(x, y, direction))
			{
				var skillArea:SkillArea = super.createMySkillArea(x, y, direction)
				for (var tankIdStr:String in getPlayState().tanks)
				{
					var otherTank:TankSprite = getPlayState().tanks[tankIdStr];
					if (otherTank != null && (tankId > 0 && otherTank.tankId < 0 || tankId < 0 && otherTank.tankId > 0))
					{
						if (skillArea.contain(otherTank.x + PlayState.TILE_WIDTH / 2, otherTank.y + PlayState.TILE_WIDTH / 2))
						{
							coolDown += 10;
							return true;
						}
					}
				}
				coolDown += 1;
			}
			return false;
		}
		
		public override function discharge(x:int, y:int, direction:int):void
		{
			getPlayState().addTankEffect(tankId, tankId, 6, 1, 1, 1, true);
			TweenLite.delayedCall(1, killSelf);
			TweenLite.delayedCall(1, super.discharge, [x, y, direction]);
		}
		
		private function killSelf():void
		{
			if (getOwner() != null)
				getPlayState().killTank(tankId,tankId);
		}
		
	}
}